/**
 * 费用结算单
 */

app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
	var gridId = $scope.gridId;
	
	$scope.bindBtn = function(event) {
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: "",
					pbid : "",
					vgsbmout : "",
					vgsjcout : "",
					vgsbmin : "",
					vgsjcin : "",
					baseInfoType : "",
					amount : "0",
					remark : "",

				});
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	}
}



app.controller('formSelfCtrl', ['$scope', '$http', FormSelfController]);
function FormSelfController($scope, $http){

	//监听子表数字输入框变更
	$scope.subGrid.numberChange = function(row, field) {
		if (field == 'amount') {

			//计算总金额
			var amount = 0 ;
			if($scope.subGrid.sonlist!=null && $scope.subGrid.sonlist.length>0){
				for(var i=0;i<$scope.subGrid.sonlist.length;i++){
					if($scope.subGrid.sonlist[i].amount){
						amount = amount+parseFloat($scope.subGrid.sonlist[i].amount);
					}
				}
			}

			//回填
			$scope.valueMap['totalAmount'] = amount.toFixed(2);
		}
	}


}
